<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Welcome</title>

<script type="text/javascript" src="dojo-release-1.7.1/dojo/dojo.js" djConfig="parseOnLoad:true"></script>

<link rel="stylesheet" type="text/css"	href="dojo-release-1.7.1/dijit/themes/tundra/tundra.css">
	
<script type="text/javascript" src="restService.js"></script>
	
<script type="text/javascript">
	dojo.require("dojo.parser");
</script>

<script type="text/javascript">

	var showAllProject = function(data){
		
		var jsonData = dojo.fromJson(data);
		
		var select = dojo.create("select",{
			id: "selector",
			onchange: selectProject,
		});
		
		var emptyOpt = dojo.create("option",{});
		select.appendChild(emptyOpt);
		
		
		for(var i=0; i<jsonData.Project.length; i++){
			
			var opt = dojo.create("option", {innerHTML: jsonData.Project[i].projectName, value: jsonData.Project[i].id});
			select.appendChild(opt);
		}
	
		dojo.byId("load").appendChild(select);
		
	}
	
	var selectProject = function(){
		
		projectSelectedId = dojo.byId("selector").value;
		
		var projectSelectedJSON = dojo.fromJson("{'dataProvider':'','guiDescriptor':'','id':"+projectSelectedId+",'projectName':''}");
		
		wsPost(	"http://localhost:8282/GUIEngine/rest/ws/loadProject", 
				projectSelectedJSON, 
				generateGUI,
				{
					"Content-Type": "application/json",
        		}
			);
		
	}
	var generateGUI = function(data){

		var form = dojo.create("form",{
			method:"post",
			action: "index.jsp",
			onSubmit: "return false;",
		});
		
		var input = dojo.create("input",{
			name: "project",
			value: data,
		});
		
		form.appendChild(input);
		form.submit();
	}

</script>

</head>

<body class="tundra" style="background-color: #272727;" >

<div id="chooseOption" style=" position: absolute; width:700px; height:150px; fixed; top: 50%; left: 50%; margin-left: -350px; margin-top: -75px;">
	<button style="width: 300px; height: 100px; font-size: 25px;" onclick="location.href='index.jsp'">Create new project</button>
	<button style="width: 300px; height: 100px; font-size: 25px;" onclick="loadProjects('http://localhost:8282/GUIEngine/rest/ws/loadAllProjects');">Load a project</button>
	
	<div id="load" style="padding-top: 20px;"></div>
</div>


</body>
</html>